#include "modelextendel.h"

ModelExtendel::ModelExtendel(QObject *parent):
    QAbstractTableModel(parent)
{

    empno[1]="2021001";
    empno[2]="2021002";
    empno[3]="2021003";
    empno[4]="2021004";
    empno[5]="2021005";

    empname[1]="张三";
    empname[2]="李四";
    empname[3]="王五";
    empname[4]="刘山";
    empname[5]="张平";

    ModelFunc();
}

void ModelExtendel::ModelFunc()
{
    viewlisttitle<<"员工编号"<<"员工姓名"<<"所在部门";
    empindex<<1<<2<<3<<4<<5;
    empnameindex<<1<<2<<3<<4<<5;

    empdepartment<<"营销部"<<"帐务部"<<"研发部"<<"董事会"<<"后勤部";

}
int ModelExtendel:: columnCount(const QModelIndex &parent) const //列
{
   return 3;//表视图行

}
int ModelExtendel::rowCount(const QModelIndex &parent ) const //行
{
    return empindex.size();

}
QVariant ModelExtendel::data(const QModelIndex &index, int role ) const //显示数据
{
   if(index.isValid()==false)
   {
       return QVariant();//如果索引不合法，返回一个空的QVarient对象
   }

   if(role==Qt::DisplayRole)
   {
       switch(index.column())
       {
       case 0:
           return empno[empindex[index.row()]];
           break;
       case 1:
           return  empname[empnameindex[index.row()]];
           break;
       case 2:
           return empdepartment[index.row()];
           break;
       default:
           return QVariant();

       }
   }
   return QVariant();
}
QVariant ModelExtendel::headerData(int section,Qt::Orientation orientateion,int role) const // 设置表头数据
{
    if(role==Qt::DisplayRole&&orientateion==Qt::Horizontal)
    {
        return viewlisttitle[section];
    }
    return QAbstractTableModel::headerData(section,orientateion,role);
}
